<template>
	<z-paging ref="paging" :paging-style="{background: '#f7f7f7'}">
		<!-- 头部 -->
		<template slot="top">
			<u-navbar title="修改密码" autoBack bgColor="#fff" :fixed="false"></u-navbar>
		</template>

		<view class="form-box">
			<u--form :model="model1" ref="uForm" labelWidth="100">
				<u-form-item label="旧密码" prop="userInfo.OldPsw" borderBottom>
					<u--input v-model="model1.userInfo.OldPsw" type="password" border="none" inputAlign="right"
						placeholder="请输入旧密码"></u--input>
				</u-form-item>
				<u-form-item label="新密码" prop="userInfo.NewPsw" borderBottom>
					<u--input v-model="model1.userInfo.NewPsw" type="password" border="none" inputAlign="right"
						placeholder="请输入新密码"></u--input>
				</u-form-item>
				<u-form-item label="确认密码" prop="userInfo.NewPsw2">
					<u--input v-model="model1.userInfo.NewPsw2" type="password" border="none" inputAlign="right"
						placeholder="请输入确认密码"></u--input>
				</u-form-item>
			</u--form>
		</view>
		<view class="submit" @click="submit">提交</view>
		<u-toast ref="uToast"></u-toast>
	</z-paging>
</template>

<script>
	export default {
		data() {
			return {
				model1: {
					userInfo: {
						OldPsw: '',
						NewPsw: '',
						NewPsw2: '',
					},
				},
				tips: '',
			}
		},
		onReady() {

		},
		methods: {
			submit() {
				let {
					OldPsw,
					NewPsw,
					NewPsw2
				} = this.model1.userInfo
				if (uni.$u.test.isEmpty(OldPsw)) {
					this.$refs.uToast.show({
						message: "旧密码不能为空",
					})
					return;
				}
				if (uni.$u.test.isEmpty(NewPsw)) {
					this.$refs.uToast.show({
						message: "新密码不能为空",
					})
					return;
				}
				if (!/^(?=.*[a-z])(?=.*[A-Z])(?=.*\d)[^]{8,16}$/.test(NewPsw)) {
					this.$refs.uToast.show({
						message: "密码须8-16位,包含大小写字母数字",
					})
					return;
				}
				if (NewPsw != NewPsw2) {
					this.$refs.uToast.show({
						message: "两次密码不一致",
					})
					return;
				}

				uni.showLoading({
					mask: true
				});

				this.$hApi.wxUpdPassword({
					old_password: OldPsw,
					new_password: NewPsw,
				}).then(res => {
					console.log(res);
					uni.hideLoading();
					if (res.code == 200) {
						uni.showToast({
							title: '修改成功',
							icon: 'success'
						});
						setTimeout(() => {
							uni.navigateBack({
								delta: 1
							});
						}, 300)
					} else {
						uni.showToast({
							title: '修改失败',
							icon: 'error'
						});
					}
				})
			},

		}
	}
</script>

<style lang="scss" scoped>
	.form-box {
		background-color: #fff;
		padding: 0 40rpx;
		margin-top: 2rpx;
	}

	.code-desc {
		padding-left: 20rpx;
		margin-left: 20rpx;
		border-left: 2rpx solid #D3D7DB;
		color: #3B75FF;
	}

	.submit {
		margin: 134rpx 24rpx 0;
		background: #3B75FF;
		border-radius: 16rpx;
		color: #fff;
		font-size: 28rpx;
		height: 88rpx;
		line-height: 88rpx;
		text-align: center;
	}
</style>